import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../views/Layout/index.vue'
import Home from '../views/Home/index.vue'
import Login from '../views/Login/Login.vue'

//异步
const News = () => import('../views/News/index.vue')
const NewsList = () => import('../views/News/NewsList/News.vue')
const NewsVerify = () => import('../views/News/NewsVerify/index.vue')
const Advert = () => import('../views/Advert/Advert.vue')
const User = () => import('../views/User/index.vue')
//子级路由
const AddNews = () => import('../views/News/NewsList/AddNews.vue')

Vue.use(VueRouter)

const routes = [

  {
    path: '',
    component: Layout,
    //路由元信息

    children: [
      {
        path: '/',
        redirect: '/login',
        component: Login
      },
      {
        path: '/home',
        name: 'Home',
        component: Home,
        meta: {
          title: '数据统计'
        },
      },
      {
        path: '/news',
        name: 'News',
        component: News,
        redirect: '/news/news-list',
        children: [
          {
            path: 'news-list',
            name: 'NewsList',
            component: NewsList,
            meta: {
              title: '新闻列表'
            },
          }, {
            path: 'news-verify',
            name: 'NewsVerify',
            component: NewsVerify
          }
        ]
      },
      {
        path: '/add-news',
        name: 'AddNews',
        component: AddNews
      },
      {
        path: '/advert',
        name: 'Advert',
        component: Advert
      },
      {
        path: '/user',
        name: 'User',
        component: User,
        meta: {
          title: '用户列表'
        },
      },
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: Login,
    meta: {
      title: '管理员登录 '
    },
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  document.title = to.meta.title
  next()
})


export default router
